package ltd.smallwang.infrastructure.exception;

import com.alibaba.cola.exception.BizException;
import com.alibaba.cola.exception.SysException;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public enum UserErrorCode {
  /**
   * The Username password incorrect.
   */
  USERNAME_PASSWORD_INCORRECT("0001", "username or password incorrect", HttpStatus.BAD_REQUEST),
  /**
   * The Verification code is incorrect.
   */
  VERIFICATION_CODE_INCORRECT("0002", "verification code is incorrect", HttpStatus.BAD_REQUEST),
  /**
   * The Not login.
   */
  NOT_LOGIN("0003", "not login", HttpStatus.UNAUTHORIZED),
  /**
   * username is existed
   */
  USERNAME_IS_EXISTED("0004", "username is existed", HttpStatus.BAD_REQUEST),
  /**
   * password too weak
   */
  PASSWORD_TOO_WEAK("0005", "password too weak", HttpStatus.BAD_REQUEST),
  /**
   * login need verified code
   */
  LOGIN_NEED_VERIFIED_CODE("0006", "login need verified code", HttpStatus.BAD_REQUEST),
  /**
   * register need email verified code
   */
  REGISTER_NEED_VERIFIED_CODE("0007", "email verify code is error or not found", HttpStatus.BAD_REQUEST),
  /**
   * email is existed
   */
  EMAIL_IS_EXISTED("0008", "email is existed", HttpStatus.BAD_REQUEST);

  private static final String BASE_CODE = "0001";

  private final String errorCode;

  private final String errorMessage;

  private final HttpStatus httpStatus;

  UserErrorCode(String errorCode, String errorMessage, HttpStatus httpStatus) {
    this.errorCode = BASE_CODE + errorCode;
    this.errorMessage = errorMessage;
    this.httpStatus = httpStatus;
  }

  public BizException buildBizException() {
    return new BizException(errorCode, errorMessage);
  }

  public SysException buildSysException() {
    return new SysException(errorCode, errorMessage);
  }
}
